package lanqiao;

import java.util.Scanner;

public class test {
    //1540 大学里的树打药
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int tree = scan.nextInt();
        int n = scan.nextInt();
        int money=0;
        for (int i = 0; i < n; i++) {
            int start = scan.nextInt();
            int end = scan.nextInt();
            int price=scan.nextInt();
            money+=((end-start)*price+price);
        }
        System.out.println(money);
    }
}
